<div class="box box-primary">
    <div class="box-body">
        {!! Form::open(['route' => 'news.store','novalidate'=>'novalidate','id'=>'fb-form']) !!}
        @include('root.news.fields')
        {!! Form::close() !!}
    </div>
</div>

<link rel="stylesheet" href="{{ asset('vendor/simditor/styles/simditor.css') }}  ">
<link rel="stylesheet" href="{{ asset('vendor/simditor/styles/simditor-html.css') }}  ">
<script>
  $LAB
    .script("{{asset('/js/jquery.form.js')}}")
    .script("{{asset('/js/jquery.validate.min.js')}}")
    .script("{{asset('/js/jquery.validate.messages_zh.js')}}")
    .script("{{asset('vendor/simditor/scripts/module.min.js')}}")
    .script("{{asset('vendor/simditor/scripts/hotkeys.min.js')}}")
    .script("{{asset('vendor/simditor/scripts/uploader.min.js')}}")
    .script("{{asset('vendor/simditor/scripts/simditor.min.js')}}")
    .script("{{asset('vendor/simditor/scripts/beautify-html.js')}}")
    .script("{{asset('vendor/simditor/scripts/simditor-html.js')}}")
    .wait(function () {
      var editor;
      $.ajax({
        type: 'get',
        url: '/api/qiniu/token',
        success: function (res) {
          editor = new Simditor({
            textarea: $('#simditor'),
            allowedTags: ['embed'],
            allowedAttributes: {
              embed: ['src', 'type', 'allowScriptAccess', 'align', 'width', 'height', 'quality', 'allowFullScreen']
            },
            allowedStyles: {
              u: ['color', 'font-size'],
              b: ['color', 'font-size']
            },
            defaultImage: '',
            toolbar: ['title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale', 'color', '|', 'ol', 'ul', 'blockquote', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment', '|', 'html'],
            upload: {
              url: 'http://up.qiniu.com/', //上传地址
              params: {token: res.uptoken},
              fileKey: 'file', //上传input name
              connectionCount: 3,
              leaveConfirm: '正在上传文件',
              host: '{{ env("QINIU_DOMAIN") }}'
            },
            pasteImage: true
          });
        }
      });

      var validator = $('#fb-form').validate({
        rules: {
          title: {
            required: true,
            maxlength: 50
          },
          typeid: {
            required: true
          }
        },
        submitHandler: function (form) {
          $(form).ajaxSubmit({
            dataType: 'json',
            beforeSubmit: function () {
              if (editor.getValue() == '') {
                modals.error('文章内容不能为空');
                return false;
              }
              $('.fb-submit').prop('disabled', true).html('<i class="fa fa-spinner animate-spin"></i>');
            },
            success: function (response) {
              console.dir(response);
              if (response.success) {
                modals.info(response.message);
                location.href = '/root/news';
              }
              else {
                modals.error(response.message);
              }
            }
          });
        }
      });

    })
</script>




